Apache Mesos Cookbook by David Blomquist
Author:David Blomquist
Language: eng
Format: epub
Publisher: Packt Publishing
Published: 2017-08-02T10:30:12+00:00
Registering frameworks
In this recipe, we will learn how frameworks register in Mesos to receive offers and state updates.
How to do it...
We will create the scheduler.go file and implement our framework inside of it.
Before we start, we need to define some globals and imports that we will need later:
import (
"bufio"
"bytes"
"log"
"net/http"
"os"
"strconv"
"strings"
"github.com/golang/protobuf/jsonpb"
)
// Url to Mesos master scheduler API
const schedulerApiUrl = "http://10.10.10.10:5050/api/v1/scheduler"
// Current framework configuration
var frameworkInfo FrameworkInfo
// Marshaler to serialize Protobuf Message to JSON
var marshaller = jsonpb.Marshaler{
EnumsAsInts: false,
Indent: " ",
OrigName: true,
}
jsonpb.Marshaler is a part of the Golang Protobuf binding. It's responsible for converting structs into JSON. We will use it to serialize the messages we send to Mesos. It's important to use a proper Marshaler because, as you can see, generated structs have additional struct tags with serialization hints. For example, enums are stored as integers but Mesos requires them as text; the default JSON Marshaler will ignore these hints and pass them as Ints.
The next step is to define the main() function. In main, we will populate frameworkInfo with the values required to register the framework. In this simple example, we don't use security features or roles, but if we do, frameworkInfo is the place where this could be set:
func main() {
user := "root"
name := "simple_framework"
hostname, err := os.Hostname()
if err != nil {
log.Fatal(err)
}
frameworkInfo = FrameworkInfo{
User: &user,
Name: &name,
Hostname: &hostname,
FailoverTimeout: &failoverTimeout,
Checkpoint: &checkpoint,
}
log.Fatal(subscribe())
}
In the last line, we call the subscribe() function. Now it's time to implement it. This will be the biggest function. In the book example, we skipped error handling but remember that it's an important part of writing robust software in Go:
func subscribe() error {
subscribeCall := &Call{
Type: Call_SUBSCRIBE.Enum(),
Subscribe: &Call_Subscribe{FrameworkInfo: &frameworkInfo},
}
body, _ := marshaller.MarshalToString(subscribeCall)
log.Print(body)
res, _ := http.Post(schedulerApiUrl, "application/json", bytes.NewBuffer([]byte(body)))
defer res.Body.Close()
Download
This site does not store any files on its server. We only index and link to content provided by other sites. Please contact the content providers to delete copyright contents if any and email us, we'll remove relevant links or contents immediately.
Sass and Compass in Action by Wynn Netherland Nathan Weizenbaum Chris Eppstein Brandon Mathis(7789)
Grails in Action by Glen Smith Peter Ledbrook(7705)
Configuring Windows Server Hybrid Advanced Services Exam Ref AZ-801 by Chris Gill(6634)
Azure Containers Explained by Wesley Haakman & Richard Hooper(6618)
Running Windows Containers on AWS by Marcio Morales(6147)
Kotlin in Action by Dmitry Jemerov(5073)
Microsoft 365 Identity and Services Exam Guide MS-100 by Aaron Guilmette(4952)
Combating Crime on the Dark Web by Nearchos Nearchou(4536)
Management Strategies for the Cloud Revolution: How Cloud Computing Is Transforming Business and Why You Can't Afford to Be Left Behind by Charles Babcock(4422)
Microsoft Cybersecurity Architect Exam Ref SC-100 by Dwayne Natwick(4403)
The Ruby Workshop by Akshat Paul Peter Philips Dániel Szabó and Cheyne Wallace(4205)
The Age of Surveillance Capitalism by Shoshana Zuboff(3964)
Python for Security and Networking - Third Edition by José Manuel Ortega(3775)
Learn Windows PowerShell in a Month of Lunches by Don Jones(3515)
The Ultimate Docker Container Book by Schenker Gabriel N.;(3442)
Mastering Python for Networking and Security by José Manuel Ortega(3357)
Mastering Azure Security by Mustafa Toroman and Tom Janetscheck(3337)
Learn Wireshark by Lisa Bock(3327)
Blockchain Basics by Daniel Drescher(3306)
